/**
 Created by:
 muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
 At 6/13/20 11:58 AM
 */
import {Fragment, IStatefulClientInterface} from "dream_rpc";
export class VirtualChannel {
    public constructor(public name: string) {}
}
export type Channels = {
    local: VirtualChannel,
    remote: VirtualChannel
}
export interface IMessageBusServerInterface {
    /**
     * Creates new channel on server and wait other channels connection
     * @param channel Channel
     */
    create(channel: VirtualChannel): Promise<void>
    /**
     * Automatic create a channel and connect this channel to specified existing remote channel
     * @remarks
     * Through this you can communicate between specified remote channel and this local channel.
     * @param channels Channels
     */
    connect(channels: Channels): Promise<void>
    /**
     * Close this channel on this message bus connection
     * @remarks
     * This operation cases all connected channel's close.
     * @param localChannel Channel
     */
    close(localChannel: VirtualChannel): Promise<void>
    /**
     * Send data to specified channel
     * @param channelWithData Fragment({local: VirtualChannel, remote: VirtualChannel}), Fragment(data)
     */
    sendData(channelWithData: Uint8Array): Promise<void>
}

export interface IMessageBusClientInterface extends IStatefulClientInterface {
    /**
     * Call when new channel is connect to specific local channel
     * @param channels new and local Channel
     */
    onChannelConnected(channels: Channels): Promise<void>
    /**
     * Call when connected a channel that to any of channel on this connection is closed.
     * @param channels Closed channel
     */
    onChannelClosed(channels: Channels): Promise<void>
    /**
     * Call when new data is received by other channels
     * @param channelWithData Fragment({local: VirtualChannel, remote: VirtualChannel}), Fragment(data)
     */
    onDataReceived(channelWithData: Uint8Array): Promise<void>
    /**
     * Check Keep alive, server check this connection using this method. 
     */
    keepAlive(): Promise<void>
}